package com.stgl.service;

import com.stgl.dao.CampusDao;
import com.stgl.util.sendmessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.stereotype.Service;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.*;

@Service
public class CampusService {
    @Autowired
    private CampusDao campusDao;

    public List<Map<String,Object>>Search_campus(Map<String,Object>gmap)
    {
        List<Map<String,Object>>list1=campusDao.Search_campus(gmap);
        return list1;
    }

    @CacheEvict(value="school",allEntries=true)
    public Map<String,Object> del_campus(Map<String,Object>gmap)
    {
        Map<String,Object>smap=new HashMap<>();
        //查询该学校是否已经有学生
        List<Map<String,Object>>list1=campusDao.list_studentByCsid(gmap);
        if(list1.size()>0){
            smap.put("result",false);
            smap.put("msg","该学校已经有学生,不能删除!");
        }else{
            campusDao.del_campus(gmap);
            campusDao.del_userbycsid(gmap);
            smap.put("result",true);
            smap.put("msg","删除成功!");
        }
        return smap;
    }


    @CacheEvict(value="school",allEntries=true)
    public int InsertCampus(Map<String,Object>gmap)
    {
       return campusDao.InsertCampus(gmap);
    }


    @CacheEvict(value="school",allEntries=true)
    public int EditCampus(Map<String,Object>gmap)
    {
        return campusDao.EditCampus(gmap);
    }





    public List<Map<String,Object>>Search_User(Map<String,Object>gmap)
    {
        List<Map<String,Object>>list1=campusDao.Search_User(gmap);
        return list1;
    }

    public int InsertUsers(Map<String,Object>gmap)
    {
        return campusDao.InsertUsers(gmap);
    }


    public int updateUsers(Map<String,Object>gmap)
    {
        return campusDao.updateUsers(gmap);
    }




    public Map<String,Object> del_Users(Map<String,Object>gmap)
    {
        Map<String,Object>smap=new HashMap<>();
        int i=campusDao.del_Users(gmap);
        if(i>0){
            smap.put("result",true);
            smap.put("msg","删除成功!");
        }else{
            smap.put("result",false);
            smap.put("msg","删除失败!");
        }
        return smap;
    }



    public void sendmessage()
    {
       //查询1园的所有未合格的学生
      /* List<Map<String,Object>>list1=campusDao.getWhgYY();
        for(int i=0;i<list1.size();i++){
            String sname=list1.get(i).get("SNAME").toString().trim();
            String sbyy=list1.get(i).get("SBYY").toString().trim();
            String jzsj=list1.get(i).get("JZSJ").toString().trim();
            jzsj=jzsj.substring(0,11);
            String csname=list1.get(i).get("CSNAME").toString().trim();
            String param="{\"sname\":\""+sname+"\", \"csname\":\""+csname+"\", \"sbyy\":\""+sbyy+"\"}";
            //System.out.println(jzsj+","+param);
            boolean result=sendmessage.sendMsg1(jzsj, param);
            System.out.println(i+","+result);
        }*/

        //查询二园的亲子班
       /* List<Map<String,Object>>list2=campusDao.getWhgEY();
        for(int i=0;i<list2.size();i++){
            String sname=list2.get(i).get("SNAME").toString().trim();
            String sbyy=list2.get(i).get("SBYY").toString().trim();
            String jzsj=list2.get(i).get("JZSJ").toString().trim();
            jzsj=jzsj.substring(0,11);
            String csname=list2.get(i).get("CSNAME").toString().trim();
            String param="{\"sname\":\""+sname+"\", \"csname\":\""+csname+"\", \"sbyy\":\""+sbyy+"\"}";
           boolean result=sendmessage.sendMsg(jzsj, param);
           System.out.println(i+","+result);
        }*/

        //查询三园的亲子班
        /*List<Map<String,Object>>list3=campusDao.getWhgSY();
        for(int i=0;i<list3.size();i++){
            String sname=list3.get(i).get("SNAME").toString().trim();
            String sbyy=list3.get(i).get("SBYY").toString().trim();
            String jzsj=list3.get(i).get("JZSJ").toString().trim();
            jzsj=jzsj.substring(0,11);
            String csname=list3.get(i).get("CSNAME").toString().trim();
            String param="{\"sname\":\""+sname+"\", \"csname\":\""+csname+"\", \"sbyy\":\""+sbyy+"\"}";
            //System.out.println(jzsj+","+param);
            boolean result=sendmessage.sendMsg(jzsj, param);
            System.out.println(i+","+result);
        }*/
    }


    public String readfile()
    {
        String sid="";
        String filePath = "D:\\Downloads\\new";
        ArrayList<String> list= sendmessage.readFiles1(filePath, new ArrayList<String>());
        for(int i=0;i<list.size();i++){
            String img=list.get(i).toString();
            List<Map<String,Object>>list2=campusDao.getImageUrl(img);
            if(list2.size()>0){
                sid+=",'"+list2.get(0).get("SID").toString()+"'";
            }
        }
        return sid;
    }

}


